<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="models.ProductModel"%>
<%@page import="java.util.List"%>
<%@page import="models.DealModel"%>
<%@page import="admin.data.DealData"%>
<%@page import="models.StoreItemModel"%>
<%@page import="admin.data.StoreData"%>
<%@page import="models.StoreModel"%>
<%@page import="java.util.TreeMap"%>
<%
	StoreData storeData = new StoreData();
	List<StoreModel> listStore = storeData.getListStore();
	StoreItemModel storeItemModel = (StoreItemModel) request.getAttribute("storeItemModel");
	String dealId = (String) request.getAttribute("dealId");
	DealModel dealModel = (DealModel) request.getAttribute("dealModel");
	List<ProductModel> listProduct = (List<ProductModel>) request.getAttribute("listProduct");
%>
<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/form_store_item.js"></script>
<script type="text/javascript" src="/admin/js/ajax_store_item.js"></script>
<script type="text/javascript">
	var url = "http://<%=request.getServerName()+":"+request.getServerPort()%>/ajax/deal";
</script>
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/store-item/list/">Danh sách sản phẩm</a></li>
                	<li class="current"><a href="/admin/store-item/add/">Thêm sản phẩm</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">          
                	<jsp:include page="/admin/elements/message.jsp"/>                	          
            		<% if(dealId==null) { %>
            		<div class="contenttitle">
                    	<h2 class="form"><span>Thêm mới sản phẩm</span></h2>
                    </div><!--contenttitle-->
            			<form method="post" action="/admin/store-item/add/" class="stdform stdform2" id="search_deal">
            				<p>
	                        	<label>Tên Deal</label>
	                            <span class="field">
	                            	<input type="text" class="smallinput" name="dealName" id="dealName">
	                            </span>
	                        </p>
            				<p>
	                        	<label>Mã Deal</label>
	                            <span class="field">
	                            	<input type="text" class="smallinput" name="dealId" id="dealId">
	                            </span>
	                        </p>
            				<p class="stdformbutton">
            					<input type="hidden" class="smallinput" name="action" id="action" value="search_deal">            					
	                        	<button class="submit radius2">Submit</button>
	                            <input type="reset" value="Reset Button" class="reset radius2">
	                        </p>
            			</form>
            		<% } else if((storeItemModel!=null)&&(storeItemModel.getId().length())>3) { %>
            		<div class="contenttitle">
                    	<h2 class="form"><span>Nhập thêm sản phẩm</span></h2>
                    </div><!--contenttitle-->
	                    <form method="post" action="/admin/store-item/add/" class="stdform stdform2" id="add_store_item_form">	                                             
	                        <p>
	                        	<label>Tên kho hàng</label>
	                            <span class="field">
	                            	<select id="storeId" name="storeId" class="smallinput">
	                            		<% for(int i=0;i<listStore.size();i++) { %>
	                            			<option value="<%=listStore.get(i).getStoreId() %>"><%=listStore.get(i).getName() %></option>                            			
	                            		<% } %>
									</select>							
	                            </span>
	                        </p> 
	                        <p>
	                        	<label>Tên Deal</label>
	                            <span class="field">
	                            	<input id="dealName" name="dealName" class="smallinput" value="<%=storeItemModel.getDealName()%>" readonly="readonly">
	  	                         </span>
	                        </p> 
	                        <p>
	                        	<label>Loại sản phẩm</label>
	                            <span class="field">	                            
	                            	<select id="type" name="type" class="smallinput">
	                            		<% if(storeItemModel.getType()==0){ %>
	                            			<option value="0" selected="selected">VC</option>                          			
	                            		<% } else { %>
	                            			<option value="1" selected="selected">SP</option>                         			
	                            		<% } %>                           			
									</select>
	                            </span>                            
	                        </p> 
	                        <p>
	                        	<label>Tên sản phẩm</label>
	                            <span class="field">
	                            	<select id="productId" name="productId" class="smallinput">
	                            		<option value="<%=storeItemModel.getProductId() %>" selected="selected"><%=storeItemModel.getProductName() %></option>                            			
									</select>				
	                            </span>
	                        </p>                      
	                        <p>
	                        	<label>Số lượng hàng tồn kho</label>
	                            <span class="field">
	                            	<input type="text" class="smallinput" name="inventory" id="inventory" value="<%=storeItemModel.getInventory() %>" readonly="readonly">
	                            </span>
	                        </p>  
	                        <p>
	                        	<label>Số lượng hàng nhập thêm</label>
	                            <span class="field">
	                            	<input type="text" class="smallinput" name="amount" id="amount">
	                            </span>
	                        </p>              
	                        <p class="stdformbutton">
	                        	<input type="hidden" class="smallinput" name="action" id="action" value="add_old_store_item">
	                        	<button class="submit radius2">Submit</button>
	                            <input type="reset" value="Reset Button" class="reset radius2">
	                        </p>                        
	                    </form>  
            		<% } else { %>
            		<div class="contenttitle">
                    	<h2 class="form"><span>Thêm mới sản phẩm</span></h2>
                    </div><!--contenttitle-->
	                    <form method="post" action="/admin/store-item/add/" class="stdform stdform2" id="add_store_item_form">	                                             
	                        <p>
	                        	<label>Tên kho hàng</label>
	                            <span class="field">
	                            	<select id="storeId" name="storeId" class="smallinput">
	                            		<% for(int i=0;i<listStore.size();i++) { %>
	                            			<option value="<%=listStore.get(i).getStoreId() %>"><%=listStore.get(i).getName() %></option>                            			
	                            		<% } %>
									</select>							
	                            </span>
	                        </p> 
	                        <p>
	                        	<label>Tên Deal</label>
	                            <span class="field">
	                            	<input id="dealName" name="dealName" class="smallinput" value="<%=dealModel.getShortName()%>" readonly="readonly">
	  	                         </span>
	                        </p> 
	                        <p>
	                        	<label>Loại sản phẩm</label>
	                            <span class="field">	                            
	                            	<select id="type" name="type" class="smallinput">
	                            		<% if(dealModel.getProductType()==0){ %>
	                            			<option value="0" selected="selected">VC</option>                          			
	                            		<% } else { %>
	                            			<option value="1" selected="selected">SP</option>                         			
	                            		<% } %>                           			
									</select>
	                            </span>                            
	                        </p> 
	                        <p>
	                        	<label>Tên sản phẩm</label>
	                            <span class="field">
	                            	<select id="productId" name="productId" class="smallinput">
	                            		<% for(int i=0;i<listProduct.size();i++) { %>
	                            			<option value="<%=listProduct.get(i).getProductId() %>"><%=listProduct.get(i).getName() %></option>                            			
	                            		<% } %>
									</select>				
	                            </span>
	                        </p>                      
	                        <p>
	                        	<label>Số lượng hàng nhập kho</label>
	                            <span class="field">
	                            	<input type="text" class="smallinput" name="amount" id="amount">
	                            </span>
	                        </p>                
	                        <p class="stdformbutton">
	                        	<input type="hidden" class="smallinput" name="action" id="action" value="add_new_store_item">
	                        	<button class="submit radius2">Submit</button>
	                            <input type="reset" value="Reset Button" class="reset radius2">
	                        </p>                        
	                    </form>  
	                <% } %>
                    <br clear="all">
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>